package com.ogawa.base.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.ogawa.base.R;
import com.ogawa.base.utils.statusbar.SystemStatusBarUtil;
import com.yalantis.ucrop.util.ScreenUtils;


/**
 * 设置状态栏高度
 *
 */
public class StatusBarHeightView extends View {
    private int statusBarHeight;
    private int type = 0;
    private int color = Color.WHITE;

    public StatusBarHeightView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    private void init(@Nullable AttributeSet attrs) {
        if (attrs != null) {
            TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.StatusBarHeightView);
            color = typedArray.getColor(R.styleable.StatusBarHeightView_bg, getResources().getColor(R.color.status_bar_def_color));
            typedArray.recycle();
        }
        setBackgroundColor(color);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        statusBarHeight = SystemStatusBarUtil.getStatusBarHeight(getContext());
//        statusBarHeight -= ScreenUtils.dip2px(getContext(),2);
        setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
                statusBarHeight);
        setPadding(0, 0, 0, 0);
    }

}
